package com.ranjiaqi.print;

import java.io.*;

/**
 * @ClassName TestPrint
 * @Description TODO
 * @Author hp
 * @Date 2021/7/2 18:10
 * @Version 1.0
 **/
public class TestPrint {
    public static void main(String[] args) {
//        PrintWriterString();
        PrintWriterFile();
        PrintWriterFileWriter();
        PrintWriterStream();
    }

    public static void PrintWriterString() {
        try (PrintWriter printWriter = new PrintWriter("F:/java/h3.txt")) {
            printWriter.println(9999);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
    public static void PrintWriterFile() {
        File file = new File("F:/java/h4.txt");
        try (PrintWriter printWriter = new PrintWriter(file)) {
            printWriter.println(6666);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
    public static void PrintWriterFileWriter() {
        try (FileWriter fileWriter = new FileWriter("F:/java/h5.txt");
             PrintWriter printWriter = new PrintWriter(fileWriter)) {
            printWriter.println(6666);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    public static void PrintWriterStream() {
        try (FileOutputStream fileOutputStream = new FileOutputStream("F:/java/h6.txt");
             PrintWriter printWriter = new PrintWriter(fileOutputStream)) {
            printWriter.println(6666);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
